<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.global.js"></script>
</head>
<body>
    <div id="app"></div>
    
    <script>
        const Son = {
            template:`
            <h4>我是儿子:{{age}}</h4>
            `,

            // 声明接收父组件的数据
            props:["age"],

            beforeCreate() {
                console.log("beforeCreate")
            },

            created(){
                console.log("created");
            },

            beforeMount(){
                console.log("beforeMount");
            },

            // 通常在【挂载完毕】时请求网络数据
            mounted(){
                console.log("mounted");
            },

            beforeUpdate(){
                console.log("beforeUpdate");
            },

            updated(){
                console.log("updated");
            },

            // 通常在【卸载之前】时保存组件数据
            beforeUnmount(){
                console.log("beforeUnmount");
            },

            unmounted(){
                console.log("unmounted");
            }

        }

        Vue.createApp({
            template:`
            <h3>我是爹</h3>
            <son v-bind:age="age" v-if="showSon"></son>
            <button v-on:click="addAge">更新数据</button>
            <button v-on:click="switchShowSon">显隐子组件</button>
            `,

            // 声明子组件
            components:{
                Son
            },

            data(){
                return {
                    age:1,
                    showSon:true
                }
            },

            methods:{
                addAge(){
                    this.age++
                },
                switchShowSon(){
                    this.showSon = !this.showSon
                }
            }
        }).mount("#app")
    </script>
</body>
</html>